package com.alt.connector;

import android.util.Log;

public class RestClient {

	// REST Server
	public static String SVC_SERVER_IP = "192.168.1.131";
//	public static String SVC_SERVER_IP = "digipay.vn";

	private static String ORDER_SVC_PATH = "CommonSvc";
	private static String SYSTEM_SVC_PATH = "Service/SystemSvc";

	// REST Service Port
	public static int SVC_PORT = 9998;
//	public static int SVC_PORT = 8080;

	// Mobile Web Port
	public static int MWEB_PORT = 80;

	private final StateRestTemplate template = new StateRestTemplate();

	public static String applicationUrl(String relativePath) {
		String url = applicationUrl() + "/" + checkNotNull(relativePath);
		//Log.i("applicationUrl", url);
		return url;
	}

	public static String applicationSystemUrl(String relativePath) {
		String url = applicationSystemUrl() + "/" + checkNotNull(relativePath);
		Log.i("applicationSystemUrl", url);
		return url;
	}

	public static String apiUrl(String relativePath) {
		String url = applicationUrl(relativePath);
		Log.i("apiUrl", url);
		return url;
	}

	public static String systemApiUrl(String relativePath) {
		String url = applicationSystemUrl(relativePath);
		Log.i("systemApiUrl", url);
		return url;
	}

	public StateRestTemplate template() {
		return template;
	}

	public static String serverUrl() {
		return "http://" + SVC_SERVER_IP + ":" + SVC_PORT;
	}

	public static String applicationUrl() {
		return serverUrl() + "/" + ORDER_SVC_PATH;
	}

	public static String applicationSystemUrl() {
		return serverUrl() + "/" + SYSTEM_SVC_PATH;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("RestClient [\n serverUrl()=");
		builder.append(serverUrl());
		builder.append(", \n applicationUrl()=");
		builder.append(applicationUrl());
		builder.append("\n]");
		return builder.toString();
	}

	private static String checkNotNull(String value) {
		return value;
	}
}